package itextpdf;

import com.itextpdf.html2pdf.ConverterProperties;
import com.itextpdf.html2pdf.HtmlConverter;
import com.itextpdf.html2pdf.resolver.font.DefaultFontProvider;
import com.itextpdf.layout.font.FontProvider;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

public class JavaToPdf {

    private static final String DEST = "target/HelloWorld_CN_HTML.pdf";
    private static final String HTML = "template.html";
    private static final String FONT = "SimHei.ttf";


    public static void main(String[] args) throws IOException {
        //String path = JavaToPdf.class.getClass().getResource("/itextpdf").getPath();
        String path = "itextpdf";
        String pathname = path + File.separatorChar + HTML;
        File htmlSource = new File(pathname);
        File pdfDest = new File(DEST);
        FontProvider fontProvider = new DefaultFontProvider();
        fontProvider.addFont(path + File.separatorChar + FONT);
        ConverterProperties props = new ConverterProperties().setFontProvider(fontProvider);
        //HtmlConverter.convertToPdf(new FileInputStream(htmlSource), new FileOutputStream(pdfDest), props);
        Map map = new HashMap<>();
        map.put("a1","sunjt");
        map.put("a2","13121091303");
        map.put("a3","我是合同号");
        String s = PDFUtil.freemarkerRender(map, pathname);
        PDFUtil.createPDF(s,"1","2","1");
    }


}
